import theme from './theme';
import * as echarts from 'echarts/src/echarts';
import 'echarts/src/chart/gauge';
import 'echarts/src/component/tooltip';
// import 'echarts/src/component/title';
import 'echarts/src/component/legend';
import 'zrender/src/svg/svg';
/**
 * @module common/echarts/gauge
 * @author ashen
 * @description  仪表图，调用initGauge方法初始化chart
 * @requires module:common/echarts/theme
 */

/**
 * @param  {Integer} id - 页面id或者class
 * @returns {Object} 图表实例dcChart
 */
export function initGauge (id) {
  const dcChart = echarts.init(document.querySelector(id), theme, {renderer: 'svg'});
  dcChart.setOption(option);
  dcChart.showLoading();
  /*window.addEventListener('resize', function () {
    dcChart.resize();
  });*/
  return dcChart;
}
/** 导出图表配置option*/
export const option = {
  tooltip: {
    formatter: ''
  },
  toolbox: {
    feature: {
      restore: {},
      saveAsImage: {}
    }
  },
  series: [
    {
      name: '',
      type: 'gauge',
      radius: '80%',
      splitNumber: 1,
      axisLine: { //仪表盘颜色
        lineStyle: {
          width: 20,
          color: [[0.8, '#7b78f2'], [1, '#E5E6F1']]
        }
      },
      itemStyle: { //仪表盘指针样式
        normal: {
          color: '#dddddd',
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      },
      splitLine: {
        show: false
      },
      axisTick: { // 刻度样式
        show: false
      },
      detail: {formatter: ''},
      data: [{value: 100, name: ''}]
    }
  ]
};
